#include <bits/stdc++.h>
// 2025/07/16
// tag:
// Author: Forever
using namespace std;
using int64 = int64_t;
#define int long long

struct node {
    int s, t;
    bool operator<(const node& rhs) const
    {
        if (s != rhs.s)
            return s < rhs.s;
        return t < rhs.t;
    }
} a[100001];

int n;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i].s >> a[i].t;
    sort(a + 1, a + n + 1);
    int l = a[1].s, r = a[1].t;
    for (int i = 2; i <= n; i++) {
        if (a[i].s > r){
            cout << l << " " << r << endl;
            l = a[i].s, r = a[i].t;
        }
        else if (a[i].t > r)
            r = a[i].t;
    }
    cout << l << " " << r << endl;

    return 0;
}